<?php
/*
	class.Utilities.php
	auther: cooc 
	email:yemasky@msn.com
*/

class Download {
	public function fileResume($file){
	   //First, see if the file exists
	   if (!is_file($file)) { return false; }
	   
	   //Gather relevent info about file
	   $len = filesize($file);
	   $filename = basename($file);
	   $file_extension = strtolower(substr(strrchr($filename,"."),1));
	   
	   //This will set the Content-Type to the appropriate setting for the file
	   switch( $file_extension ) {
		   case "exe": $ctype="application/octet-stream"; break;
		   case "zip": $ctype="application/x-zip-compressed"; break;
		   case "rar": $ctype="application/x-rar"; break;
		   default: $ctype="application/force-download";
	   }
	   
	   //Begin writing headers
	   header("Cache-Control:");
	   header("Cache-Control: public");
	   
	   header("Content-Type: $ctype");
	   if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
		   $iefilename = preg_replace('/\./', '%2e', $filename, substr_count($filename, '.') - 1);
		   header("Content-Disposition: attachment; filename=\"$iefilename\"");
	   } else {
		   header("Content-Disposition: attachment; filename=\"$filename\"");
	   }
	   header("Accept-Ranges: bytes");
	   //header('Expires: '.gmdate("D, d M Y H:i:s", mktime(date("H")+2, date("i"), date("s"), date("m"), date("d"), date("Y"))).' GMT');
	   
	   $size=filesize($file);
	   //open the file
	   $fp=fopen("$file","rb");
	   fseek($fp,$range);
	   //start buffered download
	   while(!feof($fp)){
		   //reset time limit for big files
		   set_time_limit(0);
		   print(fread($fp,1024*8));
	   }
	   fclose($fp);
	   return true;
	}
}
?>